package cn.touna.jss.common.factory;

import cn.touna.risk.api.domain.Response;
import cn.touna.risk.api.domain.ResponseService;
import cn.touna.risk.api.enums.SystemErrorCodeEnum;

/**
 * Created by Steve.Tao on 2017/8/16.
 */
public class ResponseFactory {

    /**
     * 自动将code,message添加上
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Response<T> success(T data) {
        return new Response().success(SystemErrorCodeEnum.SYSTEM_REQUEST_SUCC, data);
    }

    public static Response fail(ResponseService responseService, String msg) {
        Response response = new Response().fail(responseService);
        response.setMsg(response.getMsg() + "," + msg);
        return response;
    }

    public static Response fail(ResponseService responseService, String msg,Object data){
        Response response = fail(responseService,msg);
        response.setData(data);
        return response;
    }

    public static Response fail(ResponseService responseService) {
        return new Response().fail(responseService);
    }

    public static Response fail(String code, String message) {
        Response response = new Response().fail();
        response.setCode(code);
        response.setMsg(message);
        return response;
    }
}
